# This is a basic workflow to help you get started with Actions

name: Destroy Workflow


on:
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

env:
  AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY }}
  AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_KEY }}

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs: 
  check-code:
    runs-on: ubuntu-latest
    # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
    # Set the working directory to vnet for the config files
    # defaults:
    #     run:
    #       shell: bash
    #       working-directory: ./vnet
    steps:
      # Checkout the repository to the GitHub Actions runner
      - name: Checkout
        uses: actions/checkout@v3
      - name: Create IAM token
        id: generation-iam-token
        uses: bigtows/yc-token@latest
        with:
          service-account-token: ${{ secrets.SERVICE_ACCOUNT_TOKEN }}
          type-token: iam
      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: ${{ secrets.TERRAFORM_VERSION }}
      - name: Terraform Destroy
        id: destroy
        env:
            TF_VAR_yc_token: ${{ steps.generation-iam-token.outputs.iam-token }}
            TF_VAR_cloud_id: ${{ secrets.YC_CLOUD_ID}}
            TF_VAR_folder_id: ${{ secrets.YC_FOLDER_ID}}
        run: terraform destroy
